package com.agent.service.impl;

import com.agent.entity.Dept;
import com.agent.entity.User;
import com.agent.page.EasyuiPage;
import com.agent.repository.DeptMapper;
import com.agent.service.IDeptService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by hg on 2019/1/25.
 */
@Service("deptServiceImpl")
public class DeptServiceImpl implements IDeptService {

    @Autowired
    DeptMapper deptMapper;

    @Override
    public Dept findOne(Map<String, String> paramMap) {
        List<Dept> list = deptMapper.findOne(paramMap);
        if(!CollectionUtils.isEmpty(list)){
            return list.get(0);
        }
        return null;
    }

    @Override
    public EasyuiPage<Dept> list(Integer page, Integer rows, Dept dept) {
        PageHelper.startPage(page, rows,true, true, true);
        List<Dept> list = deptMapper.list(dept);
        EasyuiPage<Dept> pages = new EasyuiPage<Dept>();
        pages.setRows(list);
        PageInfo<Dept> pageinfo = new PageInfo<Dept>(list);
        pages.setTotal(pageinfo.getTotal());
        return pages;
    }

    @Override
    public List<Dept> listNoPage(Dept dept) {
        return deptMapper.list(dept);
    }

    @Override
    public int insert(List<Dept> depts) {
        return deptMapper.insert(depts);
    }

    @Override
    public int deleteBySystem() {
        return deptMapper.deleteBySystem();
    }

    @Override
    public int delete(String id) {
        return deptMapper.delete(id);
    }
}
